import {
    HashRouter as Router,
    Route,
    Switch,
    Link,
    Redirect,
    hashHistory
} from "react-router-dom";
import React, { Suspense, lazy } from "react";
import Loading from "../assets/RJMart/loading";
const LoadingComp = <Loading loading={true} delay={0} tip="Loading..." />;

const SideBar = lazy(() => import("./SideBar"));
// const Header = lazy(() => import("./Header"));
// const Footer = lazy(() => import("./Footer"));

import Header from "./Header";
import Footer from "./Footer";
import ContentProtect from "@root/components/ContentProtect";
import loadingImg from "../imgs/loading.gif";

//ligw begin
const SearchResults = lazy(() =>
    import("../pages/ruijing/SearchResults/index")
);
const SupplierShop = lazy(() => import("../pages/ruijing/SupplierShop/index"));
const Statements = lazy(() => import("../pages/ruijing/Statements/index"));

const Announcement = lazy(() => import("../pages/ruijing/Announcement/index"));
const BidList = lazy(() => import("../P/pages/BidList"));
const BidDetail = lazy(() => import("../P/pages/BidDetail/BidDetail"));
const BidDetailInfo = lazy(() =>
    import("../P/pages/BidDetailInfo/BidDetailInfo")
);

// ligw end

//amy bigin
const Demo = lazy(() => import("../P/pages/Demo"));
const Login = lazy(() => import("../P/pages/Login"));
const RegisterInvite = lazy(() =>
    import("../pages/ruijing/register/RegisterInvite")
);
const SignaturePwd = lazy(() =>
    import("../pages/ruijing/SignaturePwd/SignaturePwd")
);
//amy end

//alan begin
const HelpCenter = lazy(() => import("../P/modules/Help/HelpCenter"));
const HelpProblems = lazy(() => import("../P/modules/Help/HelpProblems"));
const HelpVideo = lazy(() => import("../P/modules/Help/video"));
//alan end

// const NotFound = lazy(() => import("../pages/error/NotFound"));
const NotFound = lazy(() => import("../pages/error/NotFound"));
const IndexPage = lazy(() => import("../pages/ruijing/index/IndexPage"));
const SearchProduct = lazy(() =>
    import("../pages/ruijing/search/SearchProduct")
);
const Detail = lazy(() => import("../pages/ruijing/detail/Detail"));
const Cart = lazy(() => import("../pages/ruijing/cart/Cart"));
const OrderResults = lazy(() => import("../pages/ruijing/OrderResults/index"));
const Register = lazy(() => import("../pages/ruijing/register/Register"));
const ForGetPwd = lazy(() => import("../pages/ruijing/forgetpwd/ForGetPwd"));
const TestPage = lazy(() => import("../P/pages/LoginModal/TestPage"));
const AdActivity = lazy(() => import("../P/pages/AdActivity/AdActivity"));


class PreLoading extends React.Component {
    render() {
        return (
            <div className="search-page-loading">
                <div
                    className="h-loading-loading h-loading-default-loading"
                    delay="200"
                    role="Loading"
                >
                    <span className="h-loading-spinner h-loading-default">
                        <i className="h-loading-spinner-dot h-loading-spinner-fst-dot h-loading-default-dot" />
                        <i className="h-loading-spinner-dot h-loading-spinner-snd-dot h-loading-default-dot" />
                        <i className="h-loading-spinner-dot h-loading-spinner-trd-dot h-loading-default-dot" />
                        <i className="h-loading-spinner-dot h-loading-spinner-fth-dot h-loading-default-dot" />
                    </span>
                </div>
            </div>
        );
    }
}

const RouterConfig = () => (
    <Router history={hashHistory}>
        <Header />
        <ContentProtect>
            <Suspense
                fallback={
                    <div className="global-loading">
                        {/*<img src={loadingImg} alt="" />*/}
                        <PreLoading />
                    </div>
                }
            >
                <Switch>
                    <Route path="/" exact component={IndexPage} />
                    <Route path="/bar" component={Header} />
                    <Route
                        path="/indexPage"
                        params="?navigationBar"
                        component={IndexPage}
                    />
                    <Route
                        path="/searchProduct"
                        params="?key?brandName?casNo?suppName?minPrice?maxPrice?catId?suppId?cateFlag" //catflag
                        component={SearchProduct}
                    />
                    <Route
                        path="/detail"
                        params="?productId?suppId?groupProductId"
                        component={Detail}
                    />
                    <Route path="/cart" component={Cart} />
                    <Route
                        path="/orderResults"
                        params="?isGroupbuying?step"
                        component={OrderResults}
                    />
                    <Route
                        path="/register"
                        params="?registerType?step?email?password?confirmPassword?token?key"
                        component={Register}
                    />
                    <Route
                        path="/forgetpwd"
                        params="?registerType?forgetPwd?step?findWay?account?token"
                        component={ForGetPwd}
                    />
                    <Route
                        path="/adActivity"
                        // params="?registerType?forgetPwd?step?findWay?account?token"
                        component={AdActivity}
                    />
                    {/* ligw begin */}
                    <Route
                        path="/searchResults"
                        params="?supp"
                        component={SearchResults}
                    />
                    <Route
                        path="/supplierShop"
                        params="?suppId?suppName?keyword?categoryId"
                        component={SupplierShop}
                    />
                    <Route
                        path="/statements"
                        params="?ids" //购物车商品id字符串，多个id以逗号分隔1200,1201
                        component={Statements}
                    />
                    <Route path="/testmlogin" component={TestPage} />
                    <Route path="/bidList" component={BidList} />
                    <Route
                        path="/bidDetail"
                        params="?id"
                        component={BidDetail}
                    />
                    <Route
                        path="/bidDetailInfo"
                        params="?id?unitId"
                        component={BidDetailInfo}
                    />
                    <Route path="/announcement" component={Announcement} />
                    <Route path="/demo" component={Demo} />
                    {/* ligw end */}

                    {/* amy begin */}
                    <Route path="/Login" exact component={Login} />
                    <Route
                        path="/registerInvite"
                        params="?loginSite?registerType?suppName?token"
                        component={RegisterInvite}
                    />
                    <Route
                        path="/SignaturePwd"
                        params="?step?phone?token"
                        component={SignaturePwd}
                    />

                    {/* amy end */}

                {/* alan begin */}
                <Route path="/HelpCenter"
                       params={"?search"} //帮助中心首页入参
                       component={HelpCenter} />
                <Route path="/HelpVideo"
                       params={"?vSearch"} //帮助中心视频教程入参
                       component={HelpVideo} />
                <Route
                    path="/HelpProblems"
                    params={"?columnId?articleId?targetType?publishTime?search"} //帮助中心常见问题的入参
                    component={HelpProblems} />
                {/* alan end */}

                    <Route path="/404" component={NotFound} />
                    <Redirect from="*" to="/404" />
                </Switch>
            </Suspense>
        </ContentProtect>
        <Footer />
    </Router>
);

export default RouterConfig;
